import { _decorator, Component, Node } from 'cc';
import { GEvent } from '../Event/GEvent';
import { DataToUiEvent } from '../Event/DataToUiEvent';
const { ccclass, property } = _decorator;

@ccclass('DB')
export class DB {
    //
    public gEvent:GEvent;

    private static _instance:DB;


    public constructor(){
        this.gEvent = new GEvent();
    }

    public static getInstnace():DB{
        if(null == this._instance){
            this._instance = new DB();
        }
        return this._instance;
    }

    /**
     * 添加事件监听
     * @param eventName 
     * @param fn  this.fn.bind(this)
     * @param tag 
     */
    public addEventListener(eventName:string, fn:Function, tagToRemove:any=null):string{
        return this.gEvent.addEventListener(eventName, fn, tagToRemove);
    }

    /**
     * 派发事件
     * @param event 
     */
    public dispatchEvent(event:DataToUiEvent):void{
        this.gEvent.dispatchEvent(event.name, event);
    }

    /**
     * 数据准备
     */
    public prepare():void{

    }
}

